package cn.iocoder.yudao.module.infra.api.ocr.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

/**
 * OCR 识别响应 DTO
 *
 * @author 芋道源码
 */
@Schema(description = "RPC 服务 - OCR 识别响应 DTO")
@Data
public class OcrRecognizeRespDTO {

    @Schema(description = "记录 ID", example = "1")
    private Long recordId;

    @Schema(description = "识别状态：0-失败，1-成功", example = "1")
    private Integer status;

    @Schema(description = "识别的文本内容", example = "Hello World")
    private String text;

    @Schema(description = "整体置信度", example = "0.95")
    private Double confidence;

    @Schema(description = "错误信息", example = "API密钥无效")
    private String errorMsg;

    @Schema(description = "处理时间（毫秒）", example = "1500")
    private Long processTime;

    @Schema(description = "识别字段结果")
    private List<OcrFieldResult> fields;

    @Schema(description = "词汇识别结果")
    private List<WordResult> words;

    @Schema(description = "OCR 字段识别结果")
    @Data
    public static class OcrFieldResult {
        @Schema(description = "字段名称", example = "name")
        private String fieldName;

        @Schema(description = "字段值", example = "张三")
        private String fieldValue;

        @Schema(description = "置信度", example = "0.98")
        private Double confidence;
    }

    @Schema(description = "词汇识别结果")
    @Data
    public static class WordResult {
        @Schema(description = "识别文本", example = "Hello")
        private String text;

        @Schema(description = "置信度", example = "0.98")
        private Double confidence;

        @Schema(description = "文本位置")
        private Location location;
    }

    @Schema(description = "文本位置坐标")
    @Data
    public static class Location {
        @Schema(description = "左坐标", example = "100")
        private Integer left;

        @Schema(description = "上坐标", example = "50")
        private Integer top;

        @Schema(description = "宽度", example = "200")
        private Integer width;

        @Schema(description = "高度", example = "30")
        private Integer height;
    }

}